package pers.qianyu.month_202012.date_20201221;

import java.util.*;

/**
 * 剑指 Offer 09. 用两个栈实现队列
 * https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
 *
 * @author mizzle rain
 * @date 2020年12月21日20:24:08
 */
public class CQueue {
    private Deque<Integer> st1 = new LinkedList<>();
    private Deque<Integer> st2 = new LinkedList<>();

    public CQueue() {
    }

    public void appendTail(int value) {
        st1.push(value);
    }

    public int deleteHead() {
        if (st2.isEmpty()) {
            while (!st1.isEmpty()) {
                st2.push(st1.pop());
            }
        }
        return st2.isEmpty() ? -1 : st2.pop();
    }
}